using System;
using Itdavany.Objects;
using Itdavany.Utility;
using Itdavany.Data;
//using RollingKitty.Data.Design;
using Microsoft.Xna.Framework.Graphics;

namespace RollingKitty.Objects
{
    public class GameClock : Widget
    {
        private int hour, min;
        private int month, day;
        Font timefont;
        Font dayfont;
        Font monthfont;

        ClockSkin skin;

        public GameClock(ClockSkin csk)
        {
            skin = csk;

            monthfont = SharedFont.Load(skin.month_fontname);
            dayfont = SharedFont.Load(skin.day_fontname);
            timefont = SharedFont.Load(skin.time_fontname);
        }

        public void SetClockTime(int hr, int  mn) {
            hour = hr; min = mn;
        }

        public void SetClockDate(int mon, int dt) {
            month = mon; day = dt;
        }

        public void SetClock(DateTime time)
        {
            hour = time.Hour;
            min = time.Minute;
            month = time.Month;
            day = time.Day;
        }

        public override void Draw()
        {
            string monthstr = string.Format("{0}", month);
            string daystr = string.Format("{0}", day);
            string timestr = string.Format("{0}{1} : {2}{3}", hour / 10, hour % 10, min / 10, min % 10);

            DefaultSpriteBatch.Begin();

            monthfont.SpriteBatchOverride(DefaultSpriteBatch);
            dayfont.SpriteBatchOverride(DefaultSpriteBatch);
            timefont.SpriteBatchOverride(DefaultSpriteBatch);

            monthfont.DrawString(X + skin.monthx - monthfont.MeasureString(monthstr) / 2, Y + skin.monthy - monthfont.LineHeight / 2,
                    skin.month_fontcolor, monthstr);

            dayfont.DrawString(X + skin.dayx - dayfont.MeasureString(daystr) / 2, Y + skin.dayy - dayfont.LineHeight / 2,
                                skin.day_fontcolor, daystr);

            timefont.DrawString(X + skin.timex - timefont.MeasureString(timestr) / 2, Y + skin.timey - timefont.LineHeight / 2,
                                skin.time_fontcolor, timestr);

            monthfont.SpriteBatchOverride(null);
            dayfont.SpriteBatchOverride(null);
            timefont.SpriteBatchOverride(null);

            DefaultSpriteBatch.End();

            base.Draw();
        }
    }
}